﻿using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using JT809.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JTT809_2011_Service.JT809
{
    /// <summary>
    /// JT809解码
    ///  头标识	      数据头	    数据体	    CRC校验码	    尾标识
    /// BeginFlag   JT809Header   JT809Bodies    CRCCode        EndFlag
    ///    5B  	         -	          -	            -	          5D
    /// </summary>
    internal class JT809Decoder : ByteToMessageDecoder
    {
        protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
        {
            byte[] buffer = new byte[input.Capacity + 2];
            input.ReadBytes(buffer, 1, input.Capacity);
            buffer[0] = JT809Package.BEGINFLAG;
            buffer[input.Capacity + 1] = JT809Package.ENDFLAG;
            output.Add(buffer);
        }
    }
}
